﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class biz_settings : FBasePage
{


    // Methods
    private void initPage()
    {
        if ((base.GetCookie("partnerid") == null) || (base.GetCookie("partnerid") == ""))
        {
            base.Response.Redirect("login.aspx");
        }
        string s = base.GetCookie("partnerid").ToString();
        Maticsoft.Model.Partner model = new Maticsoft.BLL.Partner().GetModel(int.Parse(s));
        if (model != null)
        {
            this.partnercreateusername.Value = model.Username;
            this.settingspassword.Value = model.Password;
            this.settingspasswordconfirm.Value = model.Password;
            this.partnercreatetitle.Value = model.Title;
            this.partnercreatehomepage.Value = model.Homepage;
            this.partnercreatecontact.Value = model.Contact;
            this.partnercreateaddress.Value = model.Address;
            this.partnercreatephone.Value = model.Phone;
            this.partnercreatemobile.Value = model.Mobile;
            this.partnercreatelocation.Value = model.Location;
            this.partnercreateother.Value = model.Other;
            this.partnercreatebankname.Value = model.Bank_name;
            this.partnercreatebankuser.Value = model.Bank_user;
            this.partnercreatebankno.Value = model.Bank_no;
            this.hfPwd.Value = model.Password;
        }
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!this.Page.IsPostBack)
        {
            this.initPage();
            base.IncludeEditorJS();
        }
    }

    protected void submit_ServerClick(object sender, EventArgs e)
    {
        Maticsoft.BLL.Partner partner = new Maticsoft.BLL.Partner();
        Maticsoft.Model.Partner model = new Maticsoft.Model.Partner();
        if ((base.GetCookie("partnerid") != null) && (base.GetCookie("partnerid").ToString() != ""))
        {
            model = partner.GetModel(Convert.ToInt32(base.GetCookie("partnerid").ToString()));
        }
        if (model != null)
        {
            if (this.settingspassword.Value == "")
            {
                model.Password = this.hfPwd.Value;
            }
            else if (this.settingspassword.Value != this.settingspasswordconfirm.Value)
            {
                this.SetError("两次密码不一样！");
                base.Response.Redirect("settings.aspx");
            }
            else
            {
                model.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(this.settingspassword.Value + "@4!@#$%@", "md5");
            }
            if (this.partnercreateusername.Value != "")
            {
                model.Username = this.partnercreateusername.Value;
            }
            model.Title = this.partnercreatetitle.Value;
            model.Homepage = this.partnercreatehomepage.Value;
            model.Contact = this.partnercreatecontact.Value;
            model.Address = this.partnercreateaddress.Value;
            model.Phone = this.partnercreatephone.Value;
            model.Mobile = this.partnercreatemobile.Value;
            model.Location = this.partnercreatelocation.Value;
            model.Other = this.partnercreateother.Value;
            model.Bank_name = this.partnercreatebankname.Value;
            model.Bank_user = this.partnercreatebankuser.Value;
            model.Bank_no = this.partnercreatebankno.Value;
            partner.Update(model);
            base.SetSuccess("修改信息成功！");
            base.Response.Redirect("settings.aspx");
        }
        else
        {
            base.Response.Redirect("login.aspx");
        }
    }

}